package mp1.aop.aspect;

import mp1.aop.calculate.APICalculation;
import mp1.aop.calculate.Calculator;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {
    @Before("execution(public * mp1.service.*.*(..))")
    public void beforeDao(JoinPoint jp){
        String info="进入"+jp.getSignature()+"方法";
        info+="参数是";
        for(Object arg : jp.getArgs()){
            info+=arg+" ";
        }
        //logger.info(info);
        System.out.println(info);
        Calculator.apiCalculator.numOfUsage++;
    }

    @AfterThrowing("execution(public * mp1.service.*.*(..))")
    public void afterException(){
        Calculator.apiCalculator.num_of_exception++;
    }







}
